package org.dromara.yuanshidian.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.yuanshidian.domain.vo.Ab01NewVo;
import org.dromara.yuanshidian.domain.bo.Ab01NewBo;
import org.dromara.yuanshidian.service.IAb01NewService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 新单位信息
 *
 * @author TzhongTop
 * @date 2025-01-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/yuanshidian/ab01new")
public class Ab01NewController extends BaseController {

    private final IAb01NewService ab01NewService;

    /**
     * 查询新单位信息列表
     */
    //@SaCheckPermission("yuanshidian:ab01new:list")
    @GetMapping("/list")
    public TableDataInfo<Ab01NewVo> list(Ab01NewBo bo, PageQuery pageQuery) {
        return ab01NewService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出新单位信息列表
     */
    //@SaCheckPermission("yuanshidian:ab01new:export")
    @Log(title = "新单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Ab01NewBo bo, HttpServletResponse response) {
        List<Ab01NewVo> list = ab01NewService.queryList(bo);
        ExcelUtil.exportExcel(list, "新单位信息", Ab01NewVo.class, response);
    }

    /**
     * 获取新单位信息详细信息
     *
     * @param ID 主键
     */
    //@SaCheckPermission("yuanshidian:ab01new:query")
    @GetMapping("/{ID}")
    public R<Ab01NewVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(ab01NewService.queryById(ID));
    }

    /**
     * 新增新单位信息
     */
    //@SaCheckPermission("yuanshidian:ab01new:add")
    @Log(title = "新单位信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Ab01NewBo bo) {
        return toAjax(ab01NewService.insertByBo(bo));
    }

    /**
     * 修改新单位信息
     */
    //@SaCheckPermission("yuanshidian:ab01new:edit")
    @Log(title = "新单位信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Ab01NewBo bo) {
        return toAjax(ab01NewService.updateByBo(bo));
    }

    /**
     * 删除新单位信息
     *
     * @param IDs 主键串
     */
    //@SaCheckPermission("yuanshidian:ab01new:remove")
    @Log(title = "新单位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(ab01NewService.deleteWithValidByIds(List.of(IDs), true));
    }
}
